import { store } from "../index";
import { defineStore } from "pinia";
import { ApiFieldsList } from "@/api/common";
import { initGlobalState } from "qiankun";
const global = initGlobalState({}); // 初始化全局状态

export const useMenu = defineStore("useMenu", {
	state: () => ({
		routerList: [],
	}),
	actions: {
		async getRouterList() {
			try {
				let res = await ApiFieldsList({ menuType: 0 });
				res.forEach(item => {
					item.label = item.name;
					item.mainType = 'customer';
				});
				this.routerList = res;
				// 可以调用子应用暴露的接口更新菜单
				global.setGlobalState({
					customerMenu: res
				});
			} catch (error) {}
		},
	}
});

export const useMenuWithOut = () => {
	return useMenu(store);
};
